#include<stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <sys/times.h>
#include <sys/param.h>
#include <pthread.h>
#include <sys/time.h>
#include <sys/time.h>
#include "config.h"
#include "userdef.h"


#define A(I,J) a[((I))*n+(J)]
#define B(I,J) b[((I))*n+(J)]
#define C(I,J) c[((I))*n+(J)]

extern void PrintData(double *Array);
extern void fill(double *Array, int size);
extern void * MyMalloc(size_t size);
extern void * MyCalloc(size_t size);
extern void * Multiply(void *WorkerData);
extern double get_time();


int main(int argc, char *argv[])
{

    double *a, *b, *c;
    double TotalTime;
    int i,j,k;
    int A_Rows, B_Rows, C_Rows;
    int A_Cols, B_Cols, C_Cols;

    if (argc != 5)
    {
        fprintf(stderr, "Usage: %s <A_Rows> <A_Columns> <B_Rows> <B_Columns> \n", argv[0]);
        exit(0);
    }

    /* Read command line arguments into variables */
    A_Rows 	 = atoi(argv[1]);
    B_Rows       = atoi(argv[3]);
    A_Cols 	 = atoi(argv[2]);
    B_Cols 	 = atoi(argv[4]);
    C_Rows 	 = atoi(argv[1]);
    C_Cols       = atoi(argv[4]);

    int n 	 = A_Rows;

    /* Allocate Memory for Matrices */
    a = (DATA_TYPE *) MyCalloc(A_Rows * A_Cols * sizeof(DATA_TYPE));
    b = (DATA_TYPE *) MyCalloc(B_Rows * B_Cols * sizeof(DATA_TYPE));
    c = (DATA_TYPE *) MyCalloc(C_Rows * C_Cols * sizeof(DATA_TYPE));


    fill(a,n);
    fill(b,n);
    fill(c,n);


    TotalTime = get_time();

    for ( i=0; i<A_Rows; i++)
    {
        for (j=0; j<A_Cols; j++)
        {
            for (k=0; k<B_Rows; k++)
            {
                C(i,j) += A(i,k) * B(k,j);
            }
        }
    }

    TotalTime = get_time() - TotalTime ;
    printf("Time Taken = %6.2f\n",TotalTime);
}
